<script setup lang="ts">
import { formatNumber } from "@/utils/util";
import { onMounted, ref } from "vue-demi";
import { useRoute } from "vue-router";
import { getPlayListDetail, getPlayListAllMusic } from "@/api/content";
import MusicItem from "@/components/MusicItem/index.vue";

const { params } = useRoute();

const posInfo = ref<Record<string, any>>({});
const list = ref<any[]>([]);

onMounted(async () => {
  const { playlist } = await getPlayListDetail(params.id);
  posInfo.value = playlist;
  const { songs } = await getPlayListAllMusic({ id: playlist.id });
  list.value = songs.map((t: any) => ({
    ...t,
    alName: t.al.name,
  }));
});
</script>

<template>
  <div class="playlist-container">
    <section class="plist-header u-plhead">
      <div
        class="plhead_bg"
        :style="{
          backgroundImage: `url('${posInfo.coverImgUrl}')`,
        }"
      ></div>
      <div class="plist-wrapper">
        <div class="plist-cover">
          <img :src="posInfo.coverImgUrl" alt="" />
          <span class="sht-icon">歌单</span>
          <span class="play">
            <SvgIcon icon="earphone"></SvgIcon>
            {{ formatNumber(posInfo.playCount, 4) }}万
          </span>
        </div>
        <div class="plist-info">
          <h2 class="title">
            {{ posInfo.name }}
          </h2>
          <div class="auth-info">
            <a href="javascript:;" class="auth-lk">
              <div class="ava-wrapper u-avatar">
                <img class="u-img" :src="posInfo.creator?.avatarUrl" alt="" />
                <!-- <span class="avaicon"></span> -->
              </div>
              <span class="nickname">{{ posInfo.creator?.nickname }}</span>
            </a>
          </div>
        </div>
      </div>
    </section>
    <div class="playlist">
      <h3 class="u-smtitle">歌曲列表</h3>
      <MusicItem :list="list" :show-index="true"></MusicItem>
    </div>
  </div>
</template>

<style lang="scss" scoped>
@import "@/assets/styles/mixin";
.plist-header {
  position: relative;
  height: 380px;
  padding: 60px 30px;
  overflow: hidden;
}

.plist-wrapper {
  position: relative;
  z-index: 2;
  display: flex;

  .plist-cover {
    position: relative;
    width: 252px;
    height: 252px;
    background: #ddd;

    img {
      width: 100%;
    }

    .sht-icon {
      position: absolute;
      z-index: 3;
      top: 20px;
      left: 0;
      padding: 0 16px;
      height: 34px;
      color: #fff;
      font-size: 18px;
      text-align: center;
      line-height: 34px;
      background-color: $primary-color;
      border-top-right-radius: 34px;
      border-bottom-right-radius: 34px;
    }

    .play {
      position: absolute;
      top: 4px;
      right: 4px;
      z-index: 10;
      font-size: 24px;
      color: #fff;
    }
  }

  .plist-info {
    flex: 1;
    margin-left: 20px;

    .title {
      padding-top: 2px;
      font-size: 34px;
      line-height: 1.3;
      color: #fefefe;
      height: 88px;
      @include inline-n(2);
    }
  }

  .auth-info {
    margin-top: 16px;
  }

  .auth-lk {
    display: flex;
    align-items: center;
    color: #fff;

    .ava-wrapper {
      display: inline-block;
      position: relative;
      width: 60px;
      height: 60px;
      margin-right: 16px;
      overflow: hidden;
    }

    .nickname {
      flex: 1;
      @include in1line;
    }
  }
}
</style>
